package net.lainiao.morethread.Chapter4.demo11;

import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/4.
 */
public class Task implements Runnable {
    private String name;

    public Task(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println("Task "+name+" running");
        long duration=(long)(Math.random()*10);
        try {
            TimeUnit.SECONDS.sleep(duration);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Task "+name+" end");
    }

    @Override
    public String toString() {
        return this.name;
    }
}
